import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: zm
 * Date: 2023/5/15
 */
public class Demo35 {
    static int N = 100010;
    static int[] p = new int[N];//放上一级是谁
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        for(int i = 1; i <= n; i++)p[i] = i;
        while(m -- > 0){
            String s = scan.next();
            int a = scan.nextInt();
            int b = scan.nextInt();
            if(s.equals("M"))p[find(a)] = find(b);
            else {
                if(find(a) == find(b)) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
    public static int find(int x){
        if(p[x] == x) return x;
        return p[x] = find(p[x]);
    }

}
